package com.vidyu.businesslayer.businesscomponents;

import com.vidyu.businesslayer.businessentities.Employer;
import com.vidyu.businesslayer.businessentities.Msg;
import com.vidyu.datalayer.dataaccesscomponents.MsgDao;
import com.vidyu.servicelayer.servicedataentitties.MsgRO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: eyalsa
 * Date: 4/16/13
 * Time: 11:55 AM
 * To change this template use File | Settings | File Templates.
 */
@Component
public class MsgHandler {

    @Autowired
    private MsgDao msgDao;

    public long addMsg(MsgRO msgRO){
        long id = msgDao.save(new Msg(msgRO.getFromId(), msgRO.getToId(), msgRO.getMsg()));
        return id;
    }

    public Msg findById(long id){
        return msgDao.findById(id);
    }

    public void updateMsgStatus(MsgRO msgRO){
        Msg dbMsg = msgDao.findById(msgRO.getId());
        dbMsg.setMsgStatus(Msg.MsgStatus.valueOf(msgRO.getMsgStatus()));
        msgDao.update(dbMsg);
    }

    public List<Msg> getMsgInbox(long fromId){
        return msgDao.getAllInboxMsges(fromId);
    }
}
